<?php
class Info_logAction extends IntesysAction {
	public function _initialize(){
		parent::_initialize();
		$this->dao=D('Info');
		$_POST['site_id']=__SITEID__;	
	}
	public function index(){
		$this->listmap = 'site_id = '.__SITEID__.' and type="log" and member_id = '.$this->memberInfo['id'];
		//筛选结果并显示
        if(isset($_GET['infocategory_id'])){
			$this->listmap .= ' and infocategory_id in('.implode(',', $_GET['infocategory_id']).')';
		}
		
		if(isset($_GET['keywords'])&&$_GET['keywords']!=''){
			$this->listmap .= ' and ( title like \'%'.$_GET['keywords'].'%\' or content like \'%'.$_GET['keywords'].'%\' ) ';
		}
		
		parent::_list();

	   if($_POST['requestType']==10100011){
           die(json_encode(array('log'=>$list,'statu'=>1)));
       }else{
           $this->display();
       }
	}
	
	public function logListPlus(){
		if($this->_get('member_id')){
			$list=$this->dao->where(['site_id'=>__SITEID__,'pid'=>0, 'share' => 1])->limit(6)->Field('id,member_id,title,click,headimg,membername,likecount,content,remark')->order('likecount desc')->select();
			$this->assign('list',$list);
			$this->display();	
		}
	}
	
	public function edit(){
		if($this->_param('id')){
			$this->info=$this->dao->where('id='.$this->_param('id'))->find();
			$this->list=D('Infocategory')->where('site_id='.__SITEID__.' and member_id='.$this->UserInfo)->select();
			$this->display();	
		}
	}
	public function add(){
		$this->infocategorylist = D('Infocategory') -> where(array('site_id' => __SITEID__, 'member_id' => $this -> memberInfo['id'])) -> select();
		$this->display();	
	}
	public function logList(){
		$this->initView();
		$map['type']='log';
		$map['member_id']=session(C('USER_AUTH_KEY'));
		$map['pid']=0;
		$this->dao->getList('privateList',$this->view,$map);
		$map['pid']=['neq',0];
		$this->dao->getList('publicList',$this->view,$map);
		$this->display();	
	}
	public function update(){
		if($this->_post('id')){
            if(isset($_POST['content'])){
                //$_POST['content']=str_replace(array("\r\n","\n","\r"),'<br/>',strip_tags($_POST['content']));
            }
			parent::update();
		}
	}
	public function share(){
		if($this->_get('id')&&$this->_get('share')){
			$map['id']=$this->_get('id');
			$map['share']=$this->_get('share');
			$result=D('Info')->save($map);
			if (false !== $result) {
				echo '分享成功';
			} else {
				echo "分享失败";
			}
		}
	}
	public function insert(){
        if(IS_POST){
            $_POST['site_id'] =__SITEID__;
            if($_POST['type']!=0||!isset($_POST['type']))$_POST['type']='log';
            $_POST['datetime']=time();
            $_POST['member_id']=session(C('USER_AUTH_KEY'));
			$_POST['headimg']=$this->memberInfo['img_url'];
			$_POST['memberpositionname']=$this->memberInfo['memberpositionname'];
			$_POST['membername'] = $this->memberInfo['name'] == '' ? $this->memberInfo['nickname'] : $this->memberInfo['name'];
			$_POST['images'] = implode(',', $_POST['img_url']);
            //$_POST['content']=str_replace(array("\r\n","\n","\r"),'<br/>',strip_tags($_POST['content']));
			//D('Info')->sendMsg([['tomemberid'=>$this->UserInfo,'title'=>'日志','content'=>'您发布了一篇标题为“'.$_POST['title'].'”的日志计划！','mode'=>'WXMsg','type'=>'remind','member_name'=>$this->memberInfo['name']]]);
            parent::insert();
			/*echo json_encode(array('status'=>1,"info"=>"数据添加成功",
					"title"=>$this->insert_data.title,
					"time"=>$this->insert_data.datetime,
					"persion"=>$this->insert_data.member_id,
					"content"=>$this->insert_data.content,
					"func"=>$this->insert_data.title));*/
        }
	}
	public function delete(){
        $this->dao=$this->dao = D('Info');
		if($this->_get('id')){
			parent::delete();
		}
	}
}

